<%--
  Created by IntelliJ IDEA.
  User: Edward_yang
  Date: 2018/1/5 0005
  Time: 15:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/commons/global.jsp" %>
<html>
<head>
    <%@ include file="/commons/basejs.jsp" %>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>企业产品</title>
</head>
<body>
<script type="text/javascript">
    $(function () {
        autoCompleteDate('${path}/companyProduct/autoCompleteData.do', 'autocomplete-ajax-edit', 'companyId', 'autocomplete-ajax-edit-x');
    })

    function formatterImg(value) {
        if (value != null) {
            return '<img height="40px"  src="' + value + '" alt="" />';
        } else {
            return '';
        }
    }
    //扩展的Date的format方法(上述插件实现) 日期转换格式
    Date.prototype.format = function (format) {
        var o = {
            "M+": this.getMonth() + 1, // month
            "d+": this.getDate(), // day
            "h+": this.getHours(), // hour
            "m+": this.getMinutes(), // minute
            "s+": this.getSeconds(), // second
            "q+": Math.floor((this.getMonth() + 3) / 3), // quarter
            "S": this.getMilliseconds()
            // millisecond
        }
        if (/(y+)/.test(format))
            format = format.replace(RegExp.$1, (this.getFullYear() + "")
                .substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(format))
                format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
        return format;
    }
    //调用日期转化格式方法
    function formatDatebox(value) {

        if (value == null || value == '') {
            return '';
        }
        var dt;
        if (value instanceof Date) {
            dt = value;
        } else {
            dt = new Date(value);
        }

        return dt.format("yyyy-MM-dd hh:mm:ss");
    }
</script>
<div style="color: red" class="easyui-layout" fit="true">
    <div data-options="region:'west',split:true,border:false" title="企业产品列表" style="width:35%;">
        <table id="companyProduct_datagrid" class="easyui-datagrid"
               data-options="
		   		url:'${path}/companyProduct/companyProductList.do',
		   		fit:true,
		   		rownumbers:true,
		   		fitColumns: true,
		   		toolbar:'#companyProduct_tools',
		   		pagination:true,
		   		singleSelect:true,
		   		onClickRow:function(index, row){
		   			getCompanyProductCategory(row.id);
		   		}
		   		">
            <thead>
            <th data-options="field:'id'">ID</th>
            <th data-options="field:'companyId',width:60" hidden>企业ID</th>
            <th data-options="field:'name',width:60">产品名称</th>
            <th data-options="field:'img',width:80,formatter:formatterImg">产品图片</th>
            <th data-options="field:'price',width:30">参考价格</th>
            <th data-options="field:'companyName',width:60">企业名称</th>
            <th data-options="field:'type',width:60,formatter:function(value){
             if(value==1){
             return '私企';
             }else if(value==2){
             return '国企';
             }else if(value==3){
                return '事业';
             }
                 }">企业类型</th>
            </thead>
        </table>
        <div id="companyProduct_tools">
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-reload'"
               onclick="$('#companyProduct_datagrid').datagrid('reload') ">刷新</a>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'"
               onclick="openEditcompanyProducBox('add')">添加</a>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit'"
               onclick="openEditcompanyProducBox('update')">编辑</a>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove'"
               onclick="deleteCompanyProduct()">删除</a>
            <a id="publishactive" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-tip'"
               onclick="openIssueCompanyProduct()">发布</a>
            <label>关键词:</label>
            <input class="easyui-searchbox" data-options="prompt:'请输入产品名称|企业名称',searcher:doProductSearch" style="width:220px;"/>
        </div>
        <style type="text/css">

            .grid{font:12px arial,helvetica,sans-serif;border:0px solid #8DB2E3}
            .grid td{font:100% arial,helvetica,sans-serif;height:40px;padding:5px}
            .grid{width:100%;border-collapse:collapse}
            .grid td{border:1px solid #e0e0e0;padding-left:5px}
        </style>
        <div class="easyui-dialog" id="edit_companyProduct_dialog" title="添加企业产品" data-options="closed:true,modal:true,width:500,height:350">
            <form id="edit_companyProduct_form" method="post">
                <table class="grid" align="center" style="margin-top: 20px">
                    <input type="hidden" name="id" id="edit-id-input" />
                    <tr style="border: 10px">
                        <td><lable for="name">产品名称:</lable></td>
                        <td>
                            <input class="easyui-validatebox" name="name" data-options="required:true" style="width:200px;"/>
                        </td>
                        <td> 图片预览:</td>
                    </tr>
                    <tr >
                        <td><lable for="code">所属企业:</lable></td>
                        <td>
                            <div style="position: relative;height:60px;width: 60px" >
                                <input type="hidden" name="companyId" id="companyId" value="" />
                                <input   type="text" id="autocomplete-ajax-edit"   class="easyui-validatebox" data-options="missingMessage:'请输入企业名称',required:true"   value="" style="position: absolute; z-index: 2; background: transparent;margin: 21px 40px 0 0; width:200px;"/>
                                <input type="text" id="autocomplete-ajax-edit-x" disabled="disabled" style="color: #CCC; position: absolute; background: transparent; z-index: 1;margin: 21px 40px 0 0;width:200px;"/>
                            </div>
                        </td>
                        <td rowspan="2"><img height="60px" src="" id="tpyl"/></td>
                    </tr>
                    <tr >
                        <td><lable for="ord">产品排序:</lable></td>
                        <td>
                            <input class="easyui-validatebox" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" name="ord" data-options="required:true" style="width:200px;"/>
                        </td>
                    </tr>
                    <tr >
                        <td> <div id="upload_ue"></div>
                            产品图片</td>
                        <td><input class="easyui-validatebox" readonly="readonly" value="" type="text" id="img"    name="img" style="width:200px;"/></td>
                        <td><a href="javascript:void(0);"  class="easyui-linkbutton" data-options="iconCls:'icon-edit'" onclick="upImage();">上传图片</a></td>
                        <script type="text/javascript">
                            var _editor;
                            $(function() {
                                //重新实例化一个编辑器，防止在上面的editor编辑器中显示上传的图片或者文件
                                _editor = UE.getEditor('upload_ue',{
                                    serverUrl:"${path}/file/upload.do?compress=1"
                                });

                                _editor.ready(function () {
                                    //设置编辑器不可用
                                    // _editor.setDisabled();
                                    //隐藏编辑器，因为不会用到这个编辑器实例，所以要隐藏
                                    _editor.hide();
                                    //侦听图片上传
                                    _editor.addListener('beforeInsertImage', function (t, arg) {
                                        //有多少张图片arg.length就是多大
                                        $("#img").val(arg[0].src);
                                        $("#tpyl").attr("src",arg[0].src);
                                    });
                                });
                            });
                            //弹出图片上传的对话框
                            function upImage() {
                                var myImage = _editor.getDialog("insertimage");
                                myImage.open();
                            }
                        </script>
                    </tr>



                </table>
                <div style="margin-top: 40px;text-align: center">
                    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="editCompanyProduct()">保存</a>
                    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="$('#edit_companyProduct_dialog').dialog('close')">取消</a>
                </div>
            </form>
        </div>
        <!---发布审核弹窗-->
        <div class="easyui-dialog" id="issue_companyProduct_dialog" title="发布企业产品" data-options="closed:true,modal:true,width:700,height:360">
            <form id="issue_companyProduct_form" method="post">
                <input name="companyId" hidden><input name="productId" hidden >
                <table class="grid" align="center" style="margin-top: 20px">
                    <tr>
                        <td>套餐名称：</td>
                        <td><input name="productName" readonly></td>
                        <td>参考价格：</td>
                        <td><input id="price" name="price" readonly></td>
                    </tr>
                    <tr>
                        <td>是否指定机构：</td>
                        <td>
                            <select id="isSeller" name="flag" style="width:150px;" onchange="changeFlag(this)">
                                <option value="0">否</option>
                                <option value="1">是</option>
                            </select>
                        </td>
                        <td>人数：</td>
                        <td><input name="num"></td>
                    </tr>
                    <tr>
                        <td>体检开始时间：</td>
                        <td><input id="tjbegin" name="beginTime"  class="Wdate"  onfocus="WdatePicker({dateFmt:'yyyy/MM/dd'})" /></td>
                        <td>体检结束时间：</td>
                        <td><input id="tjend" name="endTime"  class="Wdate"  onfocus="WdatePicker({dateFmt:'yyyy/MM/dd'})" /></td>
                    </tr>
                    <tr>
                        <td>报价开始时间：</td>
                        <td><input id="bjbegin" name="offerbeginTime" class="Wdate"  onfocus="WdatePicker({dateFmt:'yyyy/MM/dd'})" /></td>
                        <td>报价结束时间：</td>
                        <td><input id="bjend" name="offerendTime" class="Wdate"  onfocus="WdatePicker({dateFmt:'yyyy/MM/dd'})" /></td>
                    </tr>
                    <tr class="isSell">
                        <td>区域：</td>
                        <td> <select id="areaId" name="areaId" style="width:150px;">
                        </select>
                        </td>
                        <td>机构类型：</td>
                        <td> <select id="labelDetailCodeTree" name="tagcode" style="width:150px;">
                                </select>
                        </td>
                    </tr>
                    <tr class="isSell" hidden>
                        <td>机构：</td>
                        <td colspan="3">
                            <input type="text" name="sellerId" id="country" value="" hidden/>
                            <input type="text" id="autocomplete-ajax" style="position: absolute; z-index: 2; background: transparent;"/>
                            <input type="text" id="autocomplete-ajax-x" disabled="disabled" style="color: #CCC; position: absolute; background: transparent; z-index: 1;"/>
                        </td>
                    </tr>
                </table>
                <div style="margin-top: 20px;text-align: center">
                    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="issueCompanyProduct()">发布</a>
                    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="$('#issue_companyProduct_dialog').dialog('close')">取消</a>
                </div>
            </form>
        </div>

        <script>
            var flag="add";
            //联动
            function getCompanyProductCategory(companyProductId) {
                $("#singleProjectCategory_datagrid").datagrid('clearSelections');
                var queryParams = {};
                queryParams.companyProductId = companyProductId;
                var options = $("#singleProjectCategory_datagrid").datagrid('getPager').data("pagination").options;
                options.pageNumber = 1;
                //重新加载
                $("#singleProjectCategory_datagrid").datagrid('options').url = "${path}/companyProduct/singleProjectCategoryList.do";
                $("#singleProjectCategory_datagrid").datagrid('options').queryParams = queryParams;
                $("#singleProjectCategory_datagrid").datagrid('reload');
            }
            //查询
            function doProductSearch(val) {
                var queryParams = {};
                queryParams.keyWord = val;
                var options = $("#companyProduct_datagrid").datagrid('getPager').data("pagination").options;
                options.pageNumber = 1;
                //重新加载
                $("#companyProduct_datagrid").datagrid('options').url = "${path}/companyProduct/companyProductList.do";
                $("#companyProduct_datagrid").datagrid('options').queryParams = queryParams;
                $("#companyProduct_datagrid").datagrid('reload');
            }
            //删除
            function deleteCompanyProduct() {
                var rowData = $("#companyProduct_datagrid").datagrid("getSelected");
                if(rowData == null){
                    $.messager.alert("系统提示","请选择一个标签","info");
                    return;
                }
            }

            //打开编辑弹框
            function openEditcompanyProducBox(str){

                if(str == "update"){
                    flag=str;
                    var rowData = $("#companyProduct_datagrid").datagrid("getSelected");
                    if(rowData == null){
                        $.messager.alert("提示","请选择一个产品","info");
                        return;
                    }
                    $("#edit_companyProduct_dialog").dialog({title: "修改企业产品"});
                    $("#edit_companyProduct_form").form("load",rowData);
                    $("#autocomplete-ajax-edit").val(rowData.companyName);
                    $("#tpyl").attr("src",rowData.img);
                    $("#companyId").val(rowData.companyId)
                }else{
                    flag=str;
                }
                $("#edit_companyProduct_dialog").dialog("open");
            }
            function editCompanyProduct() {
                $.messager.progress();
                var url = "";
                var str = "";
                if(flag == 'add'){
                    url = "${path}/companyProduct/add.do";
                    str = "添加";
                }else if(flag == 'update'){
                    url = "${path}/companyProduct/edit.do";
                    str = "修改";
                }
                $("#edit_companyProduct_form").form("submit",{
                    url:url,
                    onSubmit:function(){
                        var valid = $(this).form("validate");
                        if (!valid) {
                            $.messager.progress("close");
                        }
                        return valid;
                    },
                    success:function(data){
                        data=$.parse(data);
                        $.messager.progress("close");
                        if(data.success){
                            $("#edit_companyProduct_dialog").dialog("close");
                            $.messager.show({
                                title:"系统提示",msg:str +"成功!",
                                timeout:600,style:"left:30%;top:10%",
                                showType:"fade"
                            });
                            $("#companyProduct_datagrid").datagrid("reload");
                        }else{
                            $.messager.alert("系统提示", data.msg,"error");
                        }
                    }
                });
            }
            //打开发布弹窗
            function openIssueCompanyProduct() {
                var rowData = $("#companyProduct_datagrid").datagrid("getSelected");
                if(rowData == null){
                    $.messager.alert("系统提示","请选择一个产品","info");
                    return;
                }
                if(rowData.price==null){
                    $.messager.alert("系统提示","请先配置体检单项之后再发布","info");
                    return;
                }
                $("#issue_companyProduct_form").form("clear");
                //区域
                $('#areaId').combobox({
                    url : '${path }/companyProduct/cbCategory.do?sellerProductLabelCode=00000010',
                    valueField : 'id',
                    textField : 'name',
                    panelHeight : 'auto',
                    value:'',
                    test:'全部',
                    editable:false
                });
                //机构类型
                $('#labelDetailCodeTree').combobox({
                    url : '${path }/companyProduct/cbCategory.do?sellerProductLabelCode=00000003',
                    valueField : 'id',
                    textField : 'name',
                    panelHeight : 'auto',
                    editable:false
                });
                //注册自动补全
                $('#autocomplete-ajax').autocomplete({
                    serviceUrl: '/companyProduct/getSells.do?companyId='+rowData.companyId,
                    onSelect: function(suggestion) {
                        $('#country').val(suggestion.data);
                    },
                    onHint: function (hint) {
                        $('#autocomplete-ajax-x').val(hint);
                    }
                });
                $("#issue_companyProduct_dialog").find("[name='companyId']").val(rowData.companyId);
                $("#issue_companyProduct_dialog").find("[name='productId']").val(rowData.id);
                $("#issue_companyProduct_dialog").find("[name='productName']").val(rowData.name);
                $("#issue_companyProduct_dialog").find("#price").val(rowData.price);
                $("#issue_companyProduct_dialog").find("#isSeller").val("0");
                $('#issue_companyProduct_dialog').dialog('open');
            }
            /*切换是否指定机构*/
            function changeFlag(obj) {
                var flag = $(obj).val();
                $('#issue_companyProduct_dialog').find(".isSell").css("display","none");
                $('#issue_companyProduct_dialog').find(".isSell").eq(flag).css("display","table-row");
            }
            //发布确认
            function issueCompanyProduct() {
                $("#issue_companyProduct_form").form("submit",{
                    url:"/companyProduct/publishCompanyPoudct.do",
                    onSubmit:function(){
                        var valid = $(this).form("validate");
                        if (!valid) {
                            $.messager.progress("close");
                        }
                        return valid;
                    },
                    success:function(data){
                        data=$.parseJSON(data);
                        $.messager.progress("close");
                        if(data.success){
                            $("#issue_companyProduct_dialog").dialog("close");
                            $.messager.show({
                                title: "成功",msg:"操作成功!",
                                timeout:600,style:"left:30%;top:10%",
                                showType:"fade"
                            });
                            $("#companyProduct_datagrid").datagrid("reload");
                        }else{
                            $.messager.alert( "失败", data.msg,"error");
                        }
                    }
                });
            }
        </script>
    </div>
    <!-----------end---------->
    <div data-options="region:'center',split:true,border:false" title="单项分类列表" style="width:25%;">
        <table id="singleProjectCategory_datagrid" class="easyui-datagrid"
               data-options="
		   		fit:true,
		   		rownumbers:true,
		   		fitColumns: true,
		   		toolbar:'#singleProjectCategory_tools',
		   		pagination:true,
		   		singleSelect:true,
		   		onClickRow:function(index, row){
	                getProductSingleProject(row);
		   		}
		   		">
            <thead>
            <th data-options="field:'id'">ID</th>
            <th data-options="field:'name',width:100">名称</th>
            <th data-options="field:'ord',width:60">排序</th>

            <th data-options="field:'status',width:100,formatter:function(value){
             if(value==0){
             return '不启用';
             }else{
                return '启用';
                }
             }">是否启用</th>
            <th data-options="field:'type',width:60,formatter:function(value){
             if(value==0){
                  return '<span style=\'color:red\'>未配置</span>';
             }else{
                return '<span  style=\'color: green\'>配置</span>';
                }
                 } ">状态</th>
            <th data-options="field:'statusType',width:100,formatter:formatData">操作</th>
            </thead>
        </table>
        <div id="singleProjectCategory_tools">
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-reload'"  onclick="$('#singleProjectCategory_datagrid').datagrid('reload') ">刷新</a>
            <label>关键词:</label>
            <input class="easyui-searchbox" data-options="prompt:'请输入分类名称',searcher:dosingleProjectCategorySearch" style="width:120px;"/>
        </div>
        <script>
            function formatData(value,row,index) {
                if(value==0){
                    return "<a href='javascript:void(0)'  class='easyui-linkbutton'  data-options='iconCls:icon-edit' onclick='checkConfiguration("+index+")'>点击配置<a/>";
                }else{
                    return "<a href='javascript:void(0)'  class='easyui-linkbutton'  data-options='iconCls:icon-edit' onclick='deletecheckConfiguration("+index+")'>取消配置<a/>";
                }
            }
            //查询
            function dosingleProjectCategorySearch(val) {
                var queryParams = {};
                queryParams.keyWord = val;
                var options = $("#singleProjectCategory_datagrid").datagrid('getPager').data("pagination").options;
                options.pageNumber = 1;
                //重新加载
                $("#singleProjectCategory_datagrid").datagrid('options').url = "${path}/companyProduct/singleProjectCategoryList.do";
                $("#singleProjectCategory_datagrid").datagrid('options').queryParams = queryParams;
                $("#singleProjectCategory_datagrid").datagrid('reload');
            }
            //点击配置(添加分类)
            function checkConfiguration(index){
                $("#singleProjectCategory_datagrid").datagrid('selectRow',index);  //选中
                var row =  $("#singleProjectCategory_datagrid").datagrid('getSelected');//获取选中行
                if(row.status==0){
                    $.messager.alert("系统提示", "请启用该分类","info");
                    return;
                }
                $.ajax({
                    url:"${path}/companyProduct/checkConfiguration.do",
                    type:"post",
                    data:{companyProductId : row.companyProductId,
                        singleProjectCategoryId : row.id
                    },
                    dataType:"json",
                    success:function(data){
                        $.messager.progress("close");
                        if(data.success){
                            $.messager.show({
                                title:"系统提示",
                                msg:"配置成功!",
                                timeout:600,
                                style:"left:30%;top:10%",
                                showType:"fade"
                            });
                            reloadSingleProjectCategory(row.companyProductId);
                        }else{
                            $.messager.alert("系统提示", data.msg,"error");
                        }
                    },
                    error:function(){
                        $.messager.progress("close");
                        $.messager.alert("系统提示", "服务器连接失败!","error");
                    }
                });
            }
            //取消配置(删除分类)
            function deletecheckConfiguration(index){
                $("#singleProjectCategory_datagrid").datagrid('selectRow',index);  //选中
                var row =  $("#singleProjectCategory_datagrid").datagrid('getSelected');//获取选中行
                $.ajax({
                    url:"${path}/companyProduct/deletecheckConfiguration.do",
                    type:"post",
                    data:{companyProductId : row.companyProductId,
                        singleProjectCategoryId : row.id
                    },
                    dataType:"json",
                    success:function(data){
                        $.messager.progress("close");
                        if(data.success){
                            $.messager.show({
                                title:"系统提示",
                                msg:"取消成功!",
                                timeout:600,
                                style:"left:30%;top:10%",
                                showType:"fade"
                            });
                            reloadSingleProjectCategory(row.companyProductId);
                        }else{
                            $.messager.alert("系统提示", data.msg,"error");
                        }
                    },
                    error:function(){
                        $.messager.progress("close");
                        $.messager.alert("系统提示", "服务器连接失败!","error");
                    }
                });
            }


            // 刷新
            function  reloadSingleProjectCategory(companyProductId) {
                var queryParams = {};
                queryParams.companyProductId = companyProductId;
                var options = $("#singleProjectCategory_datagrid").datagrid('getPager').data("pagination").options;
                options.pageNumber = 1;
                //重新加载
                $("#singleProjectCategory_datagrid").datagrid('options').url = "${path}/companyProduct/singleProjectCategoryList.do";
                $("#singleProjectCategory_datagrid").datagrid('options').queryParams = queryParams;
                $("#singleProjectCategory_datagrid").datagrid('reload');
            }
            //联动查询
            function getProductSingleProject(row) {
                $("#singleProject_datagrid").datagrid('clearSelections');
                var queryParams = {};
                queryParams.companyProductId = row.companyProductId;
                queryParams.categoryId=row.id;
                var options = $("#singleProject_datagrid").datagrid('getPager').data("pagination").options;
                options.pageNumber = 1;
                //重新加载
                $("#singleProject_datagrid").datagrid('options').url = "${path}/companyProduct/productSingleProjectList.do";
                $("#singleProject_datagrid").datagrid('options').queryParams = queryParams;
                $("#singleProject_datagrid").datagrid('reload');
            }

        </script>
    </div>
    <!---end-->
        <div   data-options="region:'east',split:true,border:false"  title="单项列表" style="width:45%;">
            <table id="singleProject_datagrid" class="easyui-datagrid"
                   data-options="
		   		fit:true,
		   		rownumbers:true,
		   		fitColumns: true,
		   		toolbar:'#singleProject_tools',
		   		pagination:true,
		   		singleSelect:true,
		   		onClickRow:function(index, row){

		   		}
		   		">
                <thead>
                <th data-options="field:'id'">ID</th>
                <th data-options="field:'name',width:60">单项名称</th>
                <th data-options="field:'price',width:60">单项价格</th>
                <th data-options="field:'des',width:60">单项明细</th>
                <th data-options="field:'significance',width:60">单项意义</th>
                <th data-options="field:'ord',width:40">排序</th>
                <th data-options="field:'status',width:80,formatter:function(value){
             if(value==0){
             return '不启用';
             }else{
                return '启用';
                }
             }">是否启用</th>
                <th data-options="field:'type',width:60,formatter:function(value){
             if(value==0){
                  return '<span style=\'color:red\'>未配置</span>';
             }else{
                return '<span  style=\'color: green\'>配置</span>';
                }
                 } ">状态</th>
                <th data-options="field:'statusType',width:100,formatter:formatDataSingleProject">操作</th>
                </thead>
            </table>
            <div id="singleProject_tools">
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-reload'"  onclick="$('#singleProjectCategory_datagrid').datagrid('reload') ">刷新</a>
                <label>关键词:</label>
                <input class="easyui-searchbox" data-options="prompt:'请输入单项名称',searcher:dosingleProjectSearch" style="width:120px;"/>
            </div>
            <script>

                function formatDataSingleProject(value,row,index) {
                    if(value==0){
                        return "<a  href='javascript:void(0)'  class='easyui-linkbutton'  data-options='iconCls:icon-edit' onclick='checkSingleProjectConfiguration("+index+")'>点击配置<a/>";
                    }else{
                        return "<a href='javascript:void(0)'  class='easyui-linkbutton'  data-options='iconCls:icon-edit' onclick='deletecheckSingleProjectConfiguration("+index+")'>取消配置<a/>";
                    }
                }
                //点击配置
                function checkSingleProjectConfiguration(index) {
                    $("#singleProject_datagrid").datagrid('selectRow',index);  //选中
                    var row =  $("#singleProject_datagrid").datagrid('getSelected');//获取选中行
                    if(row.status==0){
                        $.messager.alert("系统提示", "请在单项库中启用该单项!","info");
                        return;
                    }
                    console.log(row.companyProductId);
                    $.ajax({
                        url:"${path}/companyProduct/checkSingleProject.do",
                        type:"post",
                        data:{companyProductId : row.companyProductId,
                            singleProjectCategoryId : row.singleProjectCategoryId,
                            singleProjectId:row.id
                        },
                        dataType:"json",
                        success:function(data){
                            $.messager.progress("close");
                            if(data.success){
                                $.messager.show({
                                    title:"系统提示",
                                    msg:"配置成功!",
                                    timeout:600,
                                    style:"left:30%;top:10%",
                                    showType:"fade"
                                });
                                reloadSingleProject(row.companyProductId,row.singleProjectCategoryId);
                            }else{
                                $.messager.alert("系统提示", data.msg,"error");
                            }
                        },
                        error:function(){
                            $.messager.progress("close");
                            $.messager.alert("系统提示", "服务器连接失败!","error");
                        }
                    });
                }
                //取消配置
                function deletecheckSingleProjectConfiguration(index) {
                    $("#singleProject_datagrid").datagrid('selectRow',index);  //选中
                    var row =  $("#singleProject_datagrid").datagrid('getSelected');//获取选中行
                    if(row.status==0){
                        $.messager.alert("系统提示", "请在单项库中启用该单项!","info");
                        return;
                    }
                    console.log(row);
                    $.ajax({
                        url:"${path}/companyProduct/deleteCheckSingleProject.do",
                        type:"post",
                        data:{companyProductId : row.companyProductId,
                            singleProjectId : row.id
                        },
                        dataType:"json",
                        success:function(data){
                            $.messager.progress("close");
                            if(data.success){
                                $.messager.show({
                                    title:"系统提示",
                                    msg:"取消成功!",
                                    timeout:600,
                                    style:"left:30%;top:10%",
                                    showType:"fade"
                                });
                                reloadSingleProject(row.companyProductId,row.singleProjectCategoryId);
                            }else{
                                $.messager.alert("系统提示", data.msg,"error");
                            }
                        },
                        error:function(){
                            $.messager.progress("close");
                            $.messager.alert("系统提示", "服务器连接失败!","error");
                        }
                    });
                }
                //查询
                function dosingleProjectSearch(val) {
                    var queryParams = {};
                    queryParams.keyWord = val;
                    var options = $("#singleProject_datagrid").datagrid('getPager').data("pagination").options;
                    options.pageNumber = 1;
                    //重新加载
                    $("#singleProject_datagrid").datagrid('options').url = "${path}/companyProduct/productSingleProjectList.do";
                    $("#singleProject_datagrid").datagrid('options').queryParams = queryParams;
                    $("#singleProject_datagrid").datagrid('reload');
                }
                //刷新
                function  reloadSingleProject(companyProductId,singleProjectCategoryId){
                    var queryParams = {};
                    queryParams.companyProductId = companyProductId;
                    queryParams.categoryId=singleProjectCategoryId;
                    var options = $("#singleProject_datagrid").datagrid('getPager').data("pagination").options;
                    options.pageNumber = 1;
                    //重新加载
                    $("#singleProject_datagrid").datagrid('options').url = "${path}/companyProduct/productSingleProjectList.do";
                    $("#singleProject_datagrid").datagrid('options').queryParams = queryParams;
                    $("#singleProject_datagrid").datagrid('reload');
                }
            </script>
    </div>

</div>
</body>
</html>
